﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using MvcFrameStruct.Models;
using Webdiyer.WebControls.Mvc;

namespace MvcFrameStruct.Areas.Article.Controllers
{
    public class IndexController : Controller
    {
        //Extends.ArticleExtend articleextend = new Extends.ArticleExtend();
        //
        // GET: /Article/Index/

        public ActionResult Index(int id = 1, string kword=null)
        {
            List<Models.ArticleInfo> artlist = new List<Models.ArticleInfo>();

            using (TestEntities db = new TestEntities())
            {
                var from = from art in db.Article
                           select art;

                if (kword != null)
                {
                    from = from.Where(o => o.Content.Contains(kword));
                }
                foreach (var item in from)
                {
                    Models.ArticleInfo artobj = new Models.ArticleInfo();
                    artobj.Author = item.Author;
                    artobj.Content = item.Content;
                    artobj.PubDate = (DateTime)item.PubDate;
                    artobj.Source = item.Source;
                    artobj.Title = item.Title;

                    artlist.Add(artobj);
                }
            }
            return View(new PagedList<Models.ArticleInfo>(artlist,id,1,10).ToPagedList(id,10));
        }

        public ActionResult Add()
        {
            return View();
        }
    }
}
